package com.hunt.app.filter;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;

public class JWTTokenUtil {

    public static String createToken(String userId,String password,String userLevel){
        String token = Jwts.builder()
                .setIssuer("SYYCJR") //签发者
                .signWith(SignatureAlgorithm.HS256, "yizhangguquanpin") //签名 私钥
                .claim("userId", userId) //自定义载荷属性
                .claim("password", password)
                .claim("userLevel", userLevel)
                .claim("timestamp", new Date())
                .compact();
        return token;
    }

    public static Claims parseToken(String token){
        //返回载荷信息
        Claims claims = Jwts
                .parser()
                .setSigningKey("yizhangguquanpin") //设置加密时候私钥信息 “盐”
                .parseClaimsJws(token).getBody();
        return claims;
    }
}
